from typing import Union, Optional

from fastapi import Query
from pydantic import BaseModel, Field

from like.schema_base import EmptyStrToNone


class HpRulesListIn(BaseModel):
    """首页规则列表参数"""
    sequence: Union[int, None, EmptyStrToNone] = Query()  # 序号
    sub_sequence: Union[int, None, EmptyStrToNone] = Query()  # 子序号
    category_id: Union[int, None, EmptyStrToNone] = Query()  # 规则类别
    types_id: Union[int, None, EmptyStrToNone] = Query()  # 规则形式
    source_id: Union[int, None, EmptyStrToNone] = Query()  # 规则来源
    short_content: Union[str, None] = Query()  # 规则内容
    comment: Union[str, None] = Query()  # 注释
    regex: Union[str, None] = Query()  # 正则表达式


class HpRulesExportIn(HpRulesListIn):  
    export: Union[int, None] = Query()  # 导出模式
    page_start: Optional[int] = None    # 导出起始页
    page_end: Optional[int] = None      # 导出结束页
    page_size: int = Query()            # 每页数量
    file_name: Optional[str] = None     # 导出文件名


class HpRulesDetailIn(BaseModel):
    """首页规则详情参数"""
    id: int = Query(gt=0)  # 主键


class HpRulesAddIn(BaseModel):
    """首页规则新增参数"""
    sequence: int  # 序号
    sub_sequence: int  # 子序号
    category_id: int  # 规则类别
    types_id: int  # 规则形式
    source_id: Union[int, None]  # 规则来源
    short_content: str  # 规则内容
    comment: str  # 注释
    regex: Union[str, None]  # 正则表达式


class HpRulesEditIn(BaseModel):
    """首页规则编辑参数"""
    id: Union[int, None] = Field(gt=0)  # 主键
    sequence: int  # 序号
    sub_sequence: int  # 子序号
    category_id: int  # 规则类别
    types_id: int  # 规则形式
    source_id: Union[int, None]  # 规则来源
    short_content: str  # 规则内容
    comment: str  # 注释
    regex: Union[str, None]  # 正则表达式


class HpRulesDelIn(BaseModel):
    """首页规则删除参数"""
    id: int = Field(gt=0)  # 主键


class HpRulesExcelFileInfo(BaseModel):
    file_name: str # 导出文件名
    page_end: int # 页面结束
    page_start: int # 页面开始


class HpRulesOut(BaseModel):
    """首页规则返回信息"""
    id: Optional[int]  # 主键
    sequence: int  # 序号
    sub_sequence: int  # 子序号
    category_id: int  # 规则类别
    types_id: int  # 规则形式
    source_id: Optional[int]  # 规则来源
    short_content: str  # 规则内容
    comment: Optional[str]  # 注释
    regex: Optional[str]  # 正则表达式
    create_time: Optional[int]  # 创建时间
    update_time: Optional[int]  # 更新时间

    class Config:
        orm_mode = True
